package com.sunrise.xdoc.entity;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

/**
 * Entity with code 32 characters
 * 
 * @author phamcongbang
 * 
 */
@MappedSuperclass
public abstract class AbstractCodeEntity extends AbstractAuditEntity {
	private static final long serialVersionUID = -6181674957253464888L;
	private String code;

	@Column(name = "code", nullable = false, unique = true)
	@Length(max = 32, message = "Mã số không được dài hơn 32 ký tự")
	@NotBlank(message = "Vui lòng điền mã số")
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Transient
	@Override
	public String toString() {
		return getCode();
	}
}